package own.test.service.impl;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import own.test.service.ActiveMqProducerService;
import own.test.service.DateService;


public class ActiveMqProducerServiceImpl implements ActiveMqProducerService {

	@Autowired
	private JmsTemplate jmsTemplate;
	private DateService ds = new DateServiceImpl();
	
	@Override
	public void sendMessage(String msg) {
		String destination = jmsTemplate.getDefaultDestinationName().toString();
		System.out.println(ds.getNowDateStr()+" "+destination + "发送消息："+msg);
		MessageCreator messageCreator = new MessageCreator(){

            public Message createMessage(Session session) throws JMSException {

                return session.createTextMessage(msg);
            }
            
        };
		
		jmsTemplate.send(messageCreator);
	}

}
